<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form v-if="tabsKeys == 1" size="small" :model="pageData" layout="inline">
            <CorporateSectorCascader
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item label="仓库">
              <a-select
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="pageData.b"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                :style="{ width: '240px' }"
                class="bacClass"
                @clear="onClear"
                allow-clear
                v-model="pageData.dropDownTime"
              />
            </a-form-item>
          </a-form>
          <a-form
            v-else-if="tabsKeys == 2 || tabsKeys == 4"
            size="small"
            :model="pageData"
            layout="inline"
          >
            <a-form-item label="调拨单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.f"
              />
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                :style="{ width: '240px' }"
                class="bacClass"
                @select="onSelect1"
                @clear="onClear1"
                allow-clear
                v-model="pageData.dropDownTime1"
              />
            </a-form-item>
          </a-form>
          <a-form v-if="tabsKeys == 3" size="small" :model="pageData" layout="inline">
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item label="仓库">
              <a-select
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="pageData.d"
                allow-clear
              >
                <a-option v-for="item in fhWhList2" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                :style="{ width: '240px' }"
                class="bacClass"
                @clear="onClear2"
                allow-clear
                v-model="pageData.dropDownTime2"
              />
            </a-form-item>
          </a-form>
        </div>
        <div>
          <Toolbar
            :items="toolbarList"
            @rejected="rejecteds"
            @select="selectHandler"
            @reders="redersOut"
            @del="delSles"
            @audit="audits"
            @addRk="addRk"
          >
          </Toolbar>
        </div>
      </div>

      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="gang"></div>
    </template>
    <template #pageTabel>
      <a-tabs
        :lazy-load="true"
        :justify="true"
        :default-active-key="tabsKeys"
        @change="tabsChanges"
      >
        <a-tab-pane title="已处理" :key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <a-tab-pane title="五金调拨单待处理" :key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef3"
            class="ag-theme-alpine"
            :rowData="tableDataList3"
            :columnDefs="tc3"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet3.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize3"
            @page-size-change="change3"
            style="justify-content: center"
            :page-size="fySelet3.size"
            :current="fySelet3.page"
          />
        </a-tab-pane>
        <a-tab-pane title="制具调拨单待处理" :key="4">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady4"
            @columnResized="onColumnResized4"
            @columnMoved="onColumnMoved4"
            @columnVisible="onColumnVisible4"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef4"
            class="ag-theme-alpine"
            :rowData="tableDataList4"
            :columnDefs="tc4"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet3.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize3"
            @page-size-change="change3"
            style="justify-content: center"
            :page-size="fySelet3.size"
            :current="fySelet3.page"
          />
        </a-tab-pane>
        <!-- <a-tab-pane title="车间退料入库" :key="3">
                  <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady2"
                      style="height:94%" :defaultColDef="defaultColDef2" class='ag-theme-alpine' :rowData="tableDataList2"
                      :columnDefs="tc2" :localeText="localeText1"></AgGridVuesCopys>
                  <paginationCopys :page-size-options="pagingList1" :total="fySelet.total" show-total show-jumper show-page-size
                      @change="PageSize" @page-size-change="change" style="justify-content: center" :page-size="fySelet3.size"
                      :current="fySelet3.page" />
              </a-tab-pane> -->
      </a-tabs>
    </template>

    <a-modal
      v-model:visible="cgOut.visible"
      :on-before-ok="cgHandleOk"
      @cancel="cadelvs"
      fullscreen
      :mask-closable="false"
    >
      <template #title>
        {{ cgOut.title }}
      </template>
      <div style="width: 100%; height: 730px; overflow: auto">
        <encapsulation-agrid
          :suppressRowClickSelection="true"
          ref="gridOptionRef2"
          :configaggrid="configaggrid2"
        ></encapsulation-agrid>
      </div>
    </a-modal>

    <a-drawer
      ok-text="入库"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      :height="'90%'"
      :visible="dbPageDate.showAdd"
      @ok="sideOk"
      placement="bottom"
      @cancel="sideNo"
    >
      <template #title>
        {{ dbPageDate.titles }}
      </template>
      <div>
        <a-form ref="formRef" :model="searchData" size="mini">
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="仓库编号">
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.warehouseCode"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="仓库名称"
                :rules="[{ required: true, message: '仓库必填' }]"
                field="warehouseName"
              >
                <a-input class="bacClass" disabled v-model="searchData.warehouseName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="生产车间"
                :rules="[{ required: true, message: '生产车间必填' }]"
                field="companyName"
              >
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.companyName"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="针筒"
                :rules="[{ required: true, message: '针筒必填' }]"
                field="workDrum"
              >
                <a-input disabled class="bacClass" v-model="searchData.workDrum"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="总针数"
                :rules="[{ required: true, message: '总针数必填' }]"
                field="needleNumber"
              >
                <a-input
                  disabled
                  class="bacClass"
                  v-model="searchData.needleNumber"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="适用机型"
                :rules="[{ required: true, message: '适用机型必填' }]"
                field="applyMachine"
              >
                <a-input disabled class="bacClass" v-model="searchData.applyMachine"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="备注">
                <a-input
                  class="bacClass"
                  v-model="searchData.remark"
                  :style="{ width: '250px' }"
                  disabled
                ></a-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :span="6">
                          <a-form-item label-col-flex="80px" label="机台名称">
                              <a-input class="bacClass" v-model="macObj.machineName" :style="{ width: '250px' }"
                                  disabled></a-input>
                          </a-form-item>
                      </a-col> -->
          </a-row>
          <!-- <a-row :gutter="16">
                      <a-col :span="6">
                          <a-form-item label-col-flex="80px" label="机台编号">
                              <a-input class="bacClass" v-model="macObj.machineCode" :style="{ width: '250px' }"
                                  disabled></a-input>
                          </a-form-item>
                      </a-col>
                  </a-row> -->
        </a-form>
      </div>

      <!-- <a-space style="margin-bottom:10px;">
              <a-button v-if="dbPageDate.titles != '明细'" type="primary" @click="delLine" size="mini">删除</a-button>
          </a-space> -->
      <a-table
        stripe
        :bordered="true"
        :columns="tableColumnsWl"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
      </a-table>
    </a-drawer>

    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="dbPageDate2.showAdd"
      @ok="sideOk2"
      placement="bottom"
      @cancel="sideNo2"
    >
      <template #title>
        {{ dbPageDate2.titles }}
      </template>
      <div style="width: 100%; height: 92%; overflow: auto">
        <el-scrollbar>
          <a-form ref="formRef2" layout="inline" :model="searchData2" size="mini">
            <CorporateSectorCascader
              :configCascader="configCascader3"
              @changeCascader="changeCascader3"
            />
            <a-form-item
              label="仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="fhWh"
            >
              <a-select
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData2.fhWh"
                allow-clear
              >
                <a-option v-for="item in fhWhList3" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="入库类型" field="outStockType">
              <a-select
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData2.outStockType"
                @focus="cxOutStockType"
                allow-clear
                :disabled="searchData2.fhWh == ''"
              >
                <a-option v-for="item in outStockTypeList" :value="item['typeName']">
                  {{ item['typeName'] }}
                </a-option>
              </a-select>
            </a-form-item>
          </a-form>

          <a-space style="margin-bottom: 10px">
            <a-button type="primary" @click="addLine" size="mini">新增</a-button>
            <a-button type="primary" @click="delLine2" size="mini">删除</a-button>
          </a-space>
          <div style="width: 100%; overflow: auto; height: 95%">
            <encapsulation-agrid
              :suppressRowClickSelection="true"
              ref="gridOptionRef"
              :configaggrid="configaggrid"
            ></encapsulation-agrid>
          </div>
        </el-scrollbar>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ref, reactive } from 'vue'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import WHService from '@/service/wh'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import usePermission from '@/store/modules/permission'
  import { pagingList } from '@/api/paging'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState04 } from '@/hooks/useGridState'
  import dayjs from 'dayjs'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()
  const gridOptionRef: any = ref(null)
  const tableColumns: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      slotName: 'majorCategory',
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      slotName: 'middleCategory',
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      slotName: 'subCategory',
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      slotName: 'materialCode',
      width: 320,
      cellRenderer: {
        template: `
          <a-select class="bacClass" :allowClear="true" v-model="record.materialCode" allow-search
          @click="callFocusSel2({ 'materialName': '' })" @search="callFocusSel2({ 'materialName': $event })"
          @change="callChangeWl(record, record.materialCode)">
              <a-option v-for="item in wlPageDatas.wlList" :value="item['materialCode']">
                  {{item.materialCode + "——" + item.materialName}}
                      </a-option>
                   </a-select>
          `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callFocusSel2 = (obj: any) => {
            focusSel2(obj)
          }
          const callChangeWl = (a: any, b: any) => {
            changeWl2(a, b)
          }
          return {
            record,
            callFocusSel2,
            callChangeWl,
            wlPageDatas,
          }
        },
      },
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      slotName: 'materialName',
      cellRenderer: {
        template: `
          <a-select class="bacClass" :allowClear="true" v-model="record.materialName" allow-search
                                  @click="callFocusSel2({ 'materialName': '' })" @search="callFocusSel2({ 'materialName': $event })"
                                  @change="changeWl(record, record.materialName)">
                                  <a-option v-for="item in wlPageDatas.wlList" :value="item['materialName']">{{
                                      item['materialName']
                                  }}
                                  </a-option>
                              </a-select>
          `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callFocusSel2 = (obj: any) => {
            focusSel2(obj)
          }
          const callChangeWl = (a: any, b: any) => {
            changeWl(a, b)
          }
          return {
            record,
            callFocusSel2,
            callChangeWl,
            wlPageDatas,
          }
        },
      },
    },
    {
      field: 'grade',
      headerName: '等级',
      slotName: 'grade',
      cellRenderer: {
        template: `
          <a-select @click="callGradeChange2(record)" @change="callGrachanges(record)" class="bacClass"
                              v-model="record.grade" allow-clear allow-search>
                              <a-option v-for="item in gradrList2">{{
                                  item.detailName
                              }}</a-option>
                          </a-select>
          `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callGradeChange2 = (a: any) => {
            gradeChange2(a)
          }
          const callGrachanges = (a: any) => {
            grachanges(a)
          }
          return {
            record,
            callGradeChange2,
            callGrachanges,
            gradrList2,
          }
        },
      },
    },
    {
      headerName: '数量',
      field: 'totalNum',
      slotName: 'totalNum',
      cellRenderer: {
        template: `
          <a-input-number v-model="record.totalNum" class="input-demo bacClass" :min="0" :precision="2"
                                  :max="100000000" />
          `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
    {
      headerName: '单位',
      field: 'unit',
    },
    {
      field: 'specification',
      headerName: '规格 ',
    },
  ]
  let configaggrid = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns,
    fileName: 'ReceiptCreateNewStorageReceipt',
  })
  const gridOptionRef2: any = ref(null)
  const tableColumns2: any = [
    {
      field: 'orderNo',
      headerName: '调拨单号',
      width: 150,
    },
    {
      field: 'outStockType',
      headerName: '出库类型',
      width: 150,
    },
    {
      field: 'companyName',
      headerName: '发货公司',
      width: 150,
    },
    {
      field: 'warehouseTypeName',
      headerName: '仓库类型',
      width: 150,
    },
    {
      field: 'warehouseName',
      headerName: '仓库名称',
      width: 150,
    },
    {
      field: 'inWarehouseTypeName',
      headerName: '入库仓库类型',
      width: 150,
    },
    {
      field: 'inCompanyName',
      headerName: '入库公司',
      width: 150,
    },
    {
      field: 'inWarehouseName',
      headerName: '入库仓库名称',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      field: 'totalNum',
      headerName: '数量',
      width: 150,
    },
    {
      field: 'unit',
      headerName: '单位',
      width: 150,
    },
    {
      field: 'grade',
      slotName: 'grade',
      headerName: '等级',
      fixed: 'right',
      width: 150,
      cellRenderer: {
        template: `
          <a-select
            @click="callGradeChange"
            class="bacClass"
            v-model="record.grade"
            allow-clear
            allow-search
            :disabled="cgOut.title == '调拨单入库'"
          >
            <a-option v-for="item in gradrList">{{ item.detailName }}</a-option>
          </a-select>
          `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callGradeChange = () => {
            gradeChange()
          }
          return {
            record,
            callGradeChange,
            cgOut,
            gradrList,
          }
        },
      },
    },
    {
      field: 'auditDate',
      headerName: '发货时间',
      width: 250,
    },
  ]
  let configaggrid2 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns2,
    fileName: 'ReceiptTransferOrderIntoTheWarehouse',
  })
  const toolbarList: any = ref([
    `${permissionStore.hasPermisson('zjcrk.yclcx') ? '查询' : ''}`,
    `${permissionStore.hasPermisson('zjcrk.xjrkd') ? '新建入库单' : ''}`,
    `${permissionStore.hasPermisson('zjcrk.sh') ? '审核' : ''}`,
    `${permissionStore.hasPermisson('zjcrk.sc') ? '删除' : ''}`,
  ])

  const fySelet2: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize2 = (val: any) => {
    fySelet2.page = val
    cxYcList()
  }

  const change2 = (val: any) => {
    fySelet2.size = val
    cxYcList()
  }

  const fySelet3: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize3 = (val: any) => {
    fySelet3.page = val
    cxDbsList()
  }

  const change3 = (val: any) => {
    fySelet3.size = val
    cxDbsList()
  }

  const fySelet: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet2.page = val
    zpCxList()
  }

  const change = (val: any) => {
    fySelet2.size = val
    zpCxList()
  }

  const headerShow = ref(true)

  const pageData: any = reactive({
    a: null,
    b: null,
    c: null,
    d: null,
    e: null,
    f: null,
    dropDownTime: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    dropDownTime1: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    dropDownTime2: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
  })

  const tableDataList = ref([])

  const tableDataList2 = ref([])

  const tableDataList3 = ref([])

  const tableDataList4 = ref([])

  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }

  const gridOption3 = ref()
  const colState3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
    colState3.value = params.columnApi
  }
  const gridOption4 = ref()
  const colState4 = ref()
  const gridReady4 = (params: any) => {
    gridOption4.value = params.api
    colState4.value = params.columnApi
  }

  const gridOption2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
  }

  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef3 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const defaultColDef4 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const localeText1: any = ref(localeText)

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '入库类型',
      field: 'inStockType',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    // {
    //   headerName: '采购单号',
    //   field: 'purchaseOrderNo',
    //   width: 150,
    // },
    // {
    //   headerName: '供应商名称',
    //   field: 'supplierName',
    //   width: 150,
    // },
    // {
    //   headerName: '客户名称',
    //   field: 'customerName',
    //   width: 150,
    // },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '总数',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    // {
    //   headerName: '布笼',
    //   field: 'location',
    //   width: 150,
    // },
    {
      headerName: '创建人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '修改人',
      field: 'updateName',
      width: 150,
    },
    {
      headerName: '修改时间',
      field: 'updateTime',
      width: 150,
    },
    {
      headerName: '状态',
      field: 'infoState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
              <a-button v-if="states == 2" status="success">已入库</a-button>
              <a-button v-else="states == 0" type="dashed" status="success">待审核</a-button>
              `,
        setup(props: any) {
          return {
            states: props.params.data.infoState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '待审核' : params.value == '2' ? '已入库' : ''
        },
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'companyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '仓库类型名称',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '针盘卡号',
      field: 'cardNo',
      width: 150,
    },
    {
      headerName: '适用机型',
      field: 'applyMachine',
      width: 150,
    },
    {
      headerName: '针筒',
      field: 'workDrum',
      width: 150,
    },
    {
      headerName: '总针数',
      field: 'needleNumber',
      width: 150,
    },
    {
      headerName: '是否借出',
      field: 'debitState',
      pinned: 'right',
      width: 100,
      cellRenderer: {
        template: `<span>{{states == 0 ? '否' :states == 1?'是':''}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.debitState,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '否' : params.value == '1' ? '是' : ''
        },
      },
    },
    {
      headerName: '操作',
      field: 'atous',
      pinned: 'right',
      filter: false,
      width: 200,
      cellRenderer: {
        template: `<a-space>
                  <a-button v-if="e" @click="a" type="primary">入库</a-button>
                  </a-space>
              `,
        setup(props: any) {
          const a = () => {
            rouWh(props.params.data)
          }
          return {
            a,
            e: permissionStore.hasPermisson('zjcrk.cjtlrk'),
          }
        },
      },
    },
    {
      headerName: '创建人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '修改人',
      field: 'updateName',
      width: 150,
    },
    {
      headerName: '修改时间',
      field: 'updateTime',
      width: 150,
    },
  ]

  const tc3 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '调拨单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '发货公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '入库仓库类型',
      field: 'inWarehouseTypeName',
      width: 150,
    },
    {
      headerName: '入库公司',
      field: 'inCompanyName',
      width: 150,
    },
    {
      headerName: '入库仓库名称',
      field: 'inWarehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
      valueGetter: (params: any) => {
        const grade = params.data.grade
        const allotGrade = params.data.allotGrade
        params.data.oldGrade = grade ? grade : ''
        if (grade) {
          return grade
        } else {
          return allotGrade
        }
      },
    },
    {
      headerName: '发货时间',
      field: 'auditDate',
      width: 150,
    },
  ]

  const tc4 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '调拨单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '发货公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '入库仓库类型',
      field: 'inWarehouseTypeName',
      width: 150,
    },
    {
      headerName: '入库公司',
      field: 'inCompanyName',
      width: 150,
    },
    {
      headerName: '入库仓库名称',
      field: 'inWarehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '发货时间',
      field: 'auditDate',
      width: 150,
    },
  ]
  onMounted(() => {
    updateGridState01()
    updateGridState03()
    updateGridState04()
    cxYcList()
  })
  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      cxYcList()
    } else if (tabsKeys.value == 2 || tabsKeys.value == 4) {
      cxDbsList()
    } else if (tabsKeys.value == 3) {
      zpCxList()
    }
  }

  const tabsKeys = ref(1)

  const tabsChanges = (e: any) => {
    tabsKeys.value = e
    fySelet3.page = 1
    cxDbsList()
    if (e == 1) {
      cxYcList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjcrk.yclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.xjrkd') ? '新建入库单' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.sh') ? '审核' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.sc') ? '删除' : ''}`,
      ]
    } else if (e == 2) {
      cxDbsList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjcrk.dbddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.dbddclrk') ? '入库' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.bh') ? '驳回' : ''}`,
      ]
    } else if (e == 3) {
      zpCxList()
      toolbarList.value = [`${permissionStore.hasPermisson('zjcrk.cjtlcx') ? '查询' : ''}`]
    } else if (e == 4) {
      cxDbsList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjcrk.dbddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.dbddclrk') ? '入库' : ''}`,
        `${permissionStore.hasPermisson('zjcrk.bh') ? '驳回' : ''}`,
      ]
    }
  }

  const cxDbsList = () => {
    if (pageData.dropDownTime1.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime1[0]
      var endTime = pageData.dropDownTime1[1]
    }
    if (tabsKeys.value == 2) {
      post({
        url: 'wms/ironwareInStock/getAllocatePage',
        data: {
          page: fySelet3.page,
          size: fySelet3.size,
          inWarehouseTypeName: '制具仓',
          orderNo: pageData.f,
          infoType: 2,
          infoState: 2,
          beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
          endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          setTableTotalRow(gridOption3, res.data.data, ['totalNum'])
          gridOption3.value.setRowData(res.data.data)
          tableDataList3.value = res.data.data
          fySelet3.total = res.data.total
          tableDataList3.value.forEach((item: any) => {
            item.oldGrade = item.grade
          })
        } else {
          Message.error(res.message)
        }
      })
    } else if (tabsKeys.value == 4) {
      post({
        url: 'wms/toolInStock/getAllocatePage',
        data: {
          page: fySelet3.page,
          size: fySelet3.size,
          inWarehouseTypeName: '制具仓',
          orderNo: pageData.f,
          infoType: 2,
          infoState: 2,
          beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
          endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          setTableTotalRow(gridOption4, res.data.data, ['totalNum'])
          gridOption4.value.setRowData(res.data.data)
          tableDataList4.value = res.data.data
          fySelet3.total = res.data.total
        } else {
          Message.error(res.message)
        }
      })
    }
  }

  const cxYcList = () => {
    if (pageData.dropDownTime.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime[0]
      var endTime = pageData.dropDownTime[1]
    }
    post({
      url: 'wms/toolInStock/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        companyId: pageData.a,
        warehouseId: pageData.b,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        setTableTotalRow(gridOption, res.data.data, ['totalNum'])
        gridOption.value.setRowData(res.data.data)
        tableDataList.value = res.data.data
        fySelet2.total = res.data.total
      } else {
        Message.error(res.message)
      }
    })
  }

  const redersOut = () => {
    if (tabsKeys.value == 2) {
      if (gridOption3.value.getSelectedRows().length == 0) {
        Message.error('请选择调拨单')
        return
      }
      for (let i = 0; i < gridOption3.value.getSelectedRows().length; i++) {
        for (let j = i + 1; j < gridOption3.value.getSelectedRows().length; j++) {
          if (
            gridOption3.value.getSelectedRows()[i].orderNo !=
            gridOption3.value.getSelectedRows()[j].orderNo
          ) {
            Message.error('请勾选相同调拨单入库')
            return
          }
        }
      }
      cgData2.value = JSON.parse(JSON.stringify(gridOption3.value.getSelectedRows()))
      gridOptionRef2.value.setdataListIterface(cgData2.value)
      cgData2.value.forEach((row: any) => {
        row.grade = row.grade ? row.grade : row.allotGrade
      })
      cgOut.visible = true
    } else if (tabsKeys.value == 4) {
      if (gridOption4.value.getSelectedRows().length == 0) {
        Message.error('请选择调拨单')
        return
      }
      for (let i = 0; i < gridOption4.value.getSelectedRows().length; i++) {
        for (let j = i + 1; j < gridOption4.value.getSelectedRows().length; j++) {
          if (
            gridOption4.value.getSelectedRows()[i].orderNo !=
            gridOption4.value.getSelectedRows()[j].orderNo
          ) {
            Message.error('请勾选相同调拨单入库')
            return
          }
        }
      }
      cgData2.value = JSON.parse(JSON.stringify(gridOption4.value.getSelectedRows()))
      gridOptionRef2.value.setdataListIterface(cgData2.value)
      cgOut.visible = true
    }
  }

  const cgOut = reactive({
    visible: false,
    title: '调拨单入库',
  })

  const cgHandleOk = async () => {
    if (tabsKeys.value == 2) {
      let kong = false
      for (let i = 0; i < cgData2.value.length; i++) {
        if (
          cgData2.value[i].grade == '' ||
          cgData2.value[i].grade == undefined ||
          cgData2.value[i].grade == null
        ) {
          kong = true
        }
      }
      if (kong) {
        Message.error('等级为空不能入库')
        return false
      }
      cgData2.value.forEach((res: any) => {
        res['infoType'] = 2
        res['inStockType'] = '调拨入库'
        delete res.firmId
        delete res.firm
        delete res.id
      })
      const { code, message } = await post({
        url: 'wms/toolInStock/addStock',
        data: cgData2.value,
      })

      if (code == 200) {
        cxYcList()
        cxDbsList()
        Message.success('成功')
        return true
      }

      Message.error(message)
      return false
    } else if (tabsKeys.value == 4) {
      // for (let i = 0; i < cgData2.value.length; i++) {
      //     if (cgData2.value[i].grade == '' || cgData2.value[i].grade == undefined || cgData2.value[i].grade == null) {
      //         Message.error('请选择等级')
      //         return false
      //     }
      // }
      cgData2.value.forEach((res: any) => {
        res['infoType'] = 2
        res['inStockType'] = '调拨入库'
        delete res.firmId
        delete res.firm
        delete res.id
      })
      const { code, message } = await post({
        url: 'wms/toolInStock/addStock',
        data: cgData2.value,
      })

      if (code == 200) {
        cxYcList()
        cxDbsList()
        Message.success('成功')
        return true
      }

      Message.error(message)
      return false
    }
  }

  let oneDayTime: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])
  const warehouseChange = ($event: any, record: any) => {
    if ($event != '' || $event != undefined) {
      record['warehouseId'] = Number($event.split('-')[0])
      record['warehouseName'] = $event.split('-')[1]
      return
    }
  }

  const cadelvs = () => {
    cgOut.visible = false
  }

  const delSles = () => {
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        post({
          url: 'wms/toolInStock/delete',
          data: gridOption.value.getSelectedRows().map((res: any) => res.id),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('删除成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const audits = () => {
    Modal.confirm({
      title: '系统提示',
      content: '确认审核选中的数据?',
      onOk: () => {
        post({
          url: 'wms/toolInStock/audit',
          data: {
            infoState: 2,
            infos: gridOption.value.getSelectedRows().map((res: any) => {
              return { id: res.id }
            }),
          },
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const cgData2: any = ref([])

  const gradrList: any = ref([])

  const gradeChange = () => {
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }

  const zpCxList = () => {
    if (pageData.dropDownTime2.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime2[0]
      var endTime = pageData.dropDownTime2[1]
    }
    post({
      url: 'wms/toolVessel/getPlatterPage',
      data: {
        page: fySelet.page,
        size: fySelet.size,
        debitState: 1,
        companyId: pageData.c,
        warehouseId: pageData.d,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      gridOption2.value.setRowData(res.data.data)
      tableDataList2.value = res.data.data
      fySelet.total = res.data.total
    })
  }
  let typeIds = 0

  const rouWh = (e: any) => {
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        data.details.forEach((res: any) => {
          wlListArray.value.push({
            typeIds: typeIds++,
            ...res,
          })
        })
        macObj.vesselId = e.id
        macObj.companyId = e.companyId
        dbPageDate.showAdd = true
      }
    })
  }

  const dbPageDate: any = reactive({
    showAdd: false,
    titles: '针盘入库',
  })

  const searchData: any = reactive({
    companyName: '',
    companyId: '',
    warehouseTypeName: '',
    warehouseId: null,
    warehouseName: '',
    warehouseCode: '',
    applyMachine: '',
    workDrum: '',
    needleNumber: null,
    remark: '',
  })

  const macObj = reactive({
    machineCode: '',
    machineName: '',
    vesselId: null,
    infoType: 1,
    companyId: null,
  })

  const formRef: any = ref([])

  const sideOk = async () => {
    formRef.value?.validate().then((err: any) => {
      if (!err) {
        // for (let i = 0; i < wlListArray.value.length; i++) {
        //     if (wlListArray.value[i].grade == '' || wlListArray.value[i].grade == undefined || wlListArray.value[i].grade == null) {
        //         Message.error('请选择等级')
        //         return false
        //     }
        // }
        post({
          url: 'wms/toolInStock/returnInStock',
          data: {
            stockInfo: {
              inStockType: '车间退料入库',
              companyId: searchData.companyId,
              companyName: searchData.companyName,
              warehouseTypeName: searchData.warehouseTypeName,
              warehouseId: searchData.warehouseId,
              warehouseName: searchData.warehouseName,
              vesselsId: macObj.vesselId,
            },
            addInfo: wlListArray.value,
            deleteInfo: deleteInfo.value,
          },
        }).then(({ code, message }) => {
          if (code == 200) {
            zpCxList()
            for (let item in searchData) {
              searchData[item] = null
            }
            wlListArray.value = []
            deleteInfo.value = []
            dbPageDate.showAdd = false
            Message.success('成功')
          } else {
            Message.error(message)
          }
        })
      }
    })
  }

  const wlListArray: any = ref([])

  const sideNo = () => {
    for (let item in searchData) {
      searchData[item] = null
    }
    wlListArray.value = []
    deleteInfo.value = []
    dbPageDate.showAdd = false
  }

  const deleteInfo: any = ref([])

  const selectedRowKeysWl: any = ref([])

  const delLine = () => {
    if (selectedRowKeysWl.value.length === 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }
    selectedRowKeysWl.value.forEach((e: any) => {
      wlListArray.value.forEach((o: any) => {
        if (o.typeIds == e) {
          if (o.id != undefined || o.id != null) {
            deleteInfo.value.push(o.id)
          }
        }
      })
    })
    wlListArray.value = wlListArray.value.filter(function (o: any, index: any) {
      return selectedRowKeysWl.value.indexOf(o['typeIds']) === -1
    })
  }

  const tableColumnsWl: any = [
    {
      title: '物料大类',
      dataIndex: 'majorCategory',
      key: 'majorCategory',
      width: 150,
    },
    {
      title: '物料中类',
      dataIndex: 'middleCategory',
      key: 'middleCategory',
      width: 150,
    },
    {
      title: '物料小类',
      dataIndex: 'subCategory',
      key: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
      slotName: 'grade',
    },

    {
      title: '数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
    },
  ]

  const configCascader2 = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService = new WHService()
  const fhWhList: any = whService.whList
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService.getWarhouseListByFirmId(corporateId, '制具仓')
  }

  const configCascader = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService2 = new WHService()
  const fhWhList2: any = whService.whList
  const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.d = ''
    pageData.c = corporateId
    whService2.getWarhouseListByFirmId(corporateId, '制具仓')
  }
  function addRk() {
    dbPageDate2.showAdd = true
  }

  const dbPageDate2 = reactive({
    showAdd: false,
    titles: '新建入库单',
  })
  const sideNo2 = () => {
    for (let i in searchData2) {
      searchData2[i] = ''
    }
    wlListArray2.value = []
    dbPageDate2.showAdd = false
  }
  const wlListArray2: any = ref([])
  const searchData2: any = reactive({
    fhFirm: '',
    fhFirmId: null,
    fhWh: '',
    shFirm: '',
    shFirmId: null,
    shWhType: '',
    shWh: '',
    outStockType: '',
    materialCode: '',
    materialName: '',
  })

  let typeIds2 = 0
  const addLine = () => {
    if (searchData2.fhWh == '' || searchData2.fhFirm == '') {
      Message.error('请先选择发货公司仓库')
      return
    }
    wlListArray2.value.push({
      typeIds: typeIds2++,
      majorCategory: '',
      subCategory: '',
      materialCode: '',
      unit: '',
      materialName: '',
      totalNum: 0,
    })
    gridOptionRef.value.setdataListIterface(wlListArray2.value)
  }

  const delLine2 = () => {
    if (selectedRowKeysWl2.value.length === 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }

    wlListArray2.value = wlListArray2.value.filter(function (o: any) {
      return selectedRowKeysWl2.value.indexOf(o['typeIds']) === -1
    })
  }
  const selectedRowKeysWl2: any = ref([])

  let outStockTypeList = ref([])
  //查询出库类型
  function cxOutStockType() {
    post({
      url: 'wms/stockinType/getStockinTypePara',
      data: {
        warehouseId: Number(searchData2.fhWh.split('-')[0]),
      },
    }).then((res: any) => {
      if (res.code == 200) {
        outStockTypeList.value = res.data
      }
    })
  }

  const machineNameCode: any = ref([])

  const machineNameCodeCx = () => {
    post({
      url: 'planSingle/machine/getFieldValueWms',
      data: {
        machineName: '',
        companyId: searchData2.fhFirmId,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        machineNameCode.value = data
      }
    })
  }
  const machineNameCodeChange = (e: any) => {
    searchData2.machineCode = e.split('-')[0]
    searchData2.machineName = e.split('-')[1]
  }

  const configCascader3 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })

  const whService3 = new WHService()
  const fhWhList3: any = whService3.whList
  const changeCascader3 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData2.fhWh = ''
    searchData2.fhFirmId = corporateId
    searchData2.fhFirm = corporateLabel
    whService3.getWarhouseListByFirmId(corporateId, '制具仓')
    setTimeout(() => {
      searchData2.fhWh = fhWhList3.value[0].id + '-' + fhWhList3.value[0].warehouseName
    }, 100)
  }

  const wlPageDatas: any = reactive({
    wlListL: [],
    wlListS: [],
    wlList: [],
  })

  const focusSel2 = (val: any) => {
    post({
      url: 'purchase/MaterialInfo/getFieldValueWmsNotFix',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const changeWl = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['middleCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray2.value.filter(function (o: any) {
      return o['materialName'] == record['materialName']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['middleCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialName'] == val
    })
    if (list.length > 0) {
      record['materialCode'] = list[0]['materialCode']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['middleCategory'] = list[0]['middleCategory']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(record['materialCode'], record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const changeWl2 = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['middleCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray2.value.filter(function (o: any) {
      return o['materialCode'] == record['materialCode']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['unit'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['middleCategory'] = ''
      record['subCategory'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialCode'] == val
    })
    if (list.length > 0) {
      record['materialName'] = list[0]['materialName']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['middleCategory'] = list[0]['middleCategory']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(val, record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const cxKcsl = async (val: any, val2: any) => {
    const res = await post({
      url: 'wms/ironwareStockSummary/getGoodsStockNum',
      data: {
        materialCode: val,
        grade: val2,
        warehouseId: Number(searchData2.fhWh.split('-')[0]),
      },
    })
    if (res.code == 200) {
      return res.data.totalNum
    }
  }

  const gradrList2: any = ref([])

  const gradeChange2 = (e: any) => {
    if (e.materialName == '' || e.materialCode == '') {
      Message.error('请先选择物料')
      return
    }
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList2.value = data
      }
    })
  }
  const grachanges = (e: any) => {
    cxKcsl(e['materialCode'], e['grade']).then((res: any) => {
      e['totalNum2'] = res
    })
  }

  const formRef2: any = ref()

  const sideOk2 = async () => {
    if (wlListArray2.value.length == 0) {
      Message.warning({
        content: '请新增至少一条物料信息',
        duration: 5000,
      })
      return
    }
    for (let i = 0; i < wlListArray2.value.length; i++) {
      if (wlListArray2.value[i].totalNum == 0) {
        Message.error('数量1必须大于0')
        return false
      }
      if (wlListArray2.value[i].grade == '' || wlListArray2.value[i].grade == null) {
        Message.error('等级不能为空')
        return false
      }
    }
    formRef2.value?.validate().then((err: any) => {
      if (!err) {
        // let ob={}
        // res['infoType'] = 2
        // res['inStockType'] = '调拨入库'
        // ob['addInfo']= wlListArray2.value
        // ob['warehouseId']= Number(searchData2.fhWh.split('-')[0])
        // ob['machineName']=searchData2.machineName
        // ob['machineCode']=searchData2.machineCode
        wlListArray2.value.forEach((res: any) => {
          res['infoType'] = 0
          res['inStockType'] = searchData2.outStockType
          res['warehouseId'] = Number(searchData2.fhWh.split('-')[0])
          res['warehouseName'] = searchData2.fhWh.split('-')[1]
          res['companyId'] = searchData2.fhFirmId
          res['companyName'] = searchData2.fhFirm
          res['machineName'] = searchData2.machineName
          res['machineCode'] = searchData2.machineCode
          res['warehouseTypeName'] = '制具仓'
          delete res.totalNum2
        })
        post({
          url: 'wms/toolInStock/addStock',
          data: wlListArray2.value,
        }).then(({ code, message }) => {
          if (code == 200) {
            cxYcList()
            Message.success('成功')
            for (let i in searchData2) {
              searchData2[i] = null
            }
            wlListArray2.value = []
            dbPageDate2.showAdd = false
          } else {
            Message.error(message)
          }
        })
      }
    })
  }

  const rejecteds = () => {
    if (tabsKeys.value == 2) {
      Modal.confirm({
        title: '系统提示',
        content: '确认驳回选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/audit',
            data: {
              infoState: 1,
              infos: gridOption3.value.getSelectedRows(),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxDbsList()
            } else Message.error(res.message)
          })
        },
      })
    } else if (tabsKeys.value == 4) {
      Modal.confirm({
        title: '系统提示',
        content: '确认驳回选中的数据?',
        onOk: () => {
          post({
            url: 'wms/toolOutStock/audit',
            data: {
              infoState: 1,
              infos: gridOption4.value.getSelectedRows(),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxDbsList()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const compareDate = (dateTime1: any, dateTime2: any) => {
    var formatDate1 = new Date(dateTime1)
    var formatDate2 = new Date(dateTime2)
    if (formatDate1 > formatDate2) {
      return true
    } else {
      return false
    }
  }
  const onSelect = (dateString: any, date: any) => {
    pageData.dropDownTime = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onSelect1 = (dateString: any, date: any) => {
    pageData.dropDownTime1 = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onSelect2 = (dateString: any, date: any) => {
    pageData.dropDownTime2 = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onClear = () => {
    pageData.dropDownTime = []
  }
  const onClear1 = () => {
    pageData.dropDownTime1 = []
  }
  const onClear2 = () => {
    pageData.dropDownTime2 = []
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('ToolWarehouseIn-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('ToolWarehouseIn-3', gridOption3, colState3, tc3)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }
  const { saveGridState: saveGridState04, updateGridState: updateGridState04 } =
    saveOrUpdateGridState04('ToolWarehouseIn-4', gridOption4, colState4, tc4)
  const onColumnMoved4 = () => {
    saveGridState04()
  }
  const onColumnResized4 = () => {
    saveGridState04()
  }
  const onColumnVisible4 = () => {
    saveGridState04()
  }
</script>

<style scoped>
  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  :deep(.arco-picker input) {
    padding-left: 0 !important;
  }
  :deep(.arco-picker) {
    padding-left: 0 !important;
  }
  :deep(.arco-picker-separator) {
    padding: 0 !important;
  }
</style>
<style>
  .el-scrollbar__view {
    height: 100%;
  }
</style>
